<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>新增管理员</title>
		<link rel="stylesheet" href="/static/component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="mainBox">
				<div class="main-container">
					<div class="layui-form-item">
						<label class="layui-form-label">账号</label>
						<div class="layui-input-block">
							<input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入标题"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮箱</label>
						<div class="layui-input-block">
							<input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="请输入邮箱"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="text" name="password" lay-verify="password" autocomplete="off" placeholder="请输入密码"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电话</label>
						<div class="layui-input-block">
							<input type="text" name="mobile" lay-verify="title" autocomplete="off" placeholder="请输入标题"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">性别</label>
						<div class="layui-input-block">
							<input type="radio" name="sex" value="0" title="男">
							<input type="radio" name="sex" value="1" title="女" checked>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">角色</label>
						<div class="layui-input-block">
							<select name="roleId" xm-select="demo3" xm-select-skin="normal">
								<option value="1">北京</option>
								<option value="2" selected="selected">上海</option>
								<option value="3">广州</option>
								<option value="4" selected="selected">深圳</option>
								<option value="5">天津</option>
							</select>
						</div>
					</div>
				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
						lay-filter="user-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
		<script src="/static/component/layui/layui.js"></script>
		<script src="/static/component/pear/pear.js"></script>
		<script>
			// 数据接口
			const ADMIN_ADD = "{:url('system.admin/add')}";

			layui.use(['form', 'jquery', 'upload','select'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				let upload = layui.upload;
				let select = layui.select;

				//1.渲染标签
				var addTags = select.render({
					el: '#demo3',
					name: 'demo3',
					layVerify: '',
					layVerType: 'msg',
					paging: true,
					pageSize: 5,
					data: []
				});

				form.on('submit(user-save)', function(data) {
					$.ajax({
						url: ADMIN_ADD,
						data: JSON.stringify(data.field),
						dataType: 'json',
						contentType: 'application/json',
						type: 'post',
						success: function(result) {
							if (result.code === 0) {
								layer.msg(result.msg, {
									icon: 1,
									time: 1000
								}, function() {
									parent.layer.close(parent.layer.getFrameIndex(window
										.name)); //关闭当前页
									parent.layui.table.reload("user-table");
								});
							} else {
								layer.msg(result.msg, {
									icon: 2,
									time: 1000
								});
							}
						}
					})
					return false;
				});

			})
		</script>
	</body>
</html>
